package com.ruoyi.project.management.task1.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.management.task1.domain.Task1;
import com.ruoyi.project.management.task1.service.ManagementTaskService1;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/management/task")
public class ManagementTaskController1 extends BaseController {
    @Autowired
    private ManagementTaskService1 managementTaskService1;

    private String  prefix="management/task";

    @GetMapping("")
    @RequiresPermissions("management:task:list")
    public String operlog()
    {
        return prefix + "/task";
    }

    @RequiresPermissions("management:task:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Task1 task1)
    {
        startPage();
        List<Task1> list = managementTaskService1.selectMore(task1);
        return getDataTable(list);
    }

    /**
     * 新增任务
     */
    @RequiresPermissions("management:task:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增任务保存
     */
    @RequiresPermissions("management:task:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Task1 task1)
    {
        return toAjax(managementTaskService1.insertTask(task1));
    }

    /**
     * 修改任务
     */
    @RequiresPermissions("management:task:edit")
    @GetMapping("/edit/{task_id}")
    public String edit(@PathVariable("task_id") Long task_id, ModelMap mmap)
    {
        mmap.put("task1", managementTaskService1.selectTaskById(task_id));
        return prefix + "/edit";
    }

    /**
     * 修改任务保存
     */
    @RequiresPermissions("management:task:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated Task1 task1)
    {
        return toAjax(managementTaskService1.updateTask(task1));
    }

    /**
     * 删除任务
     */
    @RequiresPermissions("management:task:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(managementTaskService1.deleteTaskByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
     * 校验岗位名称
     */
    @PostMapping("/checkTaskTitleUnique")
    @ResponseBody
    public String checkTaskTitleUnique(Task1 task1)
    {
        return managementTaskService1.checkTaskTitleUnique(task1);
    }

}

